$(function() {
	jQuery.validator.addMethod("isphone", function(value, element) {   
		return this.optional(element) || /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(value);   
	}, "请正确填写您的手机号码");
	jQuery.validator.addMethod("qqNumber", function(value, element) {   
		return this.optional(element) || /^[^0][0-9]{5,10}$/.test(value);   
	}, "请输入正确的QQ号码");
	jQuery.validator.addMethod("phoneNumber", function(value, element) {   
		return this.optional(element) || /^((0[0-9]{2,3})\-?([2-9][0-9]{6,7})+(\-[0,9]{1,4})?)|(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(value);   
	}, "请输入正确的电话号码");
	
	$("#add_customer_form").validate({
		errorPlacement:function(error,element) {  
			element.parent().find(".verror").html(error);
		},
		rules:{
			"customer.userName":{
				required:true,
				rangelength: [4, 20],
				remote: {
					url: base + "admin/customer/checkUserName.action", 
					type: "POST", 
					data: {"customer.id": ($("#customer_id").val()), "customer.userName": ($("#customer.userName").val())}
				}
			},
			"customer.realName":{
				required:true,
				rangelength: [2, 20]
			},
			"customer.phoneNumber": {
				required:true,
				phoneNumber: true
			},
			"customer.telephone":{
				isphone:true,
				rangelength: [7, 20],
				remote: {
					url: base + "admin/customer/checkTelephone.action", 
					type: "POST", 
					data: {"customer.id": ($("#customer_id").val()), "customer.telephone": ($("#customer.telephone").val())}
				}
			},
			"customer.email":{
				email:true,
				remote: {
					url: base + "admin/customer/checkEmail.action", 
					type: "POST", 
					data: {"customer.id": ($("#customer_id").val()), "customer.email": ($("#customer.email").val())}
				}
			}, 
			"customer.qqNumber": {
				qqNumber: true, 
				remote: {
					url: base + "admin/customer/checkQQNumber.action", 
					type: "POST", 
					data: {"customer.id": ($("#customer_id").val()), "customer.qqNumber": ($("#customer.qqNumber").val())}
				}
			},
			"sel0": {
				required: true
			}
		},
		messages:{
			"customer.userName": {
				required: "请输入客户昵称", 
				rangelength:"长度不能少于{0}和大于{1}个字符",
				remote: "该昵称已被使用"
			},
			"customer.realName": {
				required: "请输入真实姓名",
				rangelength: "长度不能少于{0}和大于{1}个字符"
			},
			"customer.phoneNumber": {
				required: "请输入联系电话",
				phoneNumber: "输入正确的电话号码"
			},
			"customer.telephone": {
				isphone: " 手机号码格式不正确",
				rangelength: " 长度不能少于{0}和大于{1}个字符",
				remote: " 该手机号码已被使用"
			}, 
			"customer.email": {
				email: " 电子邮箱格式不正确",
				remote: " 该邮箱已被使用"
			}, 
			"customer.qqNumber": {
				qqNumber: " QQ号码格式不正确",
				remote: " 该QQ号码已被使用"
			}, 
			"sel0": {
				required: "联系地址必选"
			}
		}
	});
});